using Demo.Net.EFCoreEnv.Dbcontexts;
using Microsoft.EntityFrameworkCore;
using Demo.Net.Model;
using IRepository;
using Iservice;
using Repository;
using service;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();


//````````````````````````````````````````````````````````````````````
builder.Services.AddCors(s=>s.AddPolicy("any",s=>s.AllowAnyMethod().AllowAnyOrigin().AllowAnyHeader()));
//依赖注入
builder.Services.AddScoped<IBaseRepository<ParkingSpace>, CarPortRepository>();
builder.Services.AddScoped<IBaseRepository<Owner>, UserRepository>();
builder.Services.AddScoped<IBaseRepository<Feedback>, FeedBackRepository>();
builder.Services.AddScoped<IBaseRepository<RentRecord>,RentRepository>();

builder.Services.AddScoped<IBaseService<ParkingSpace>, CarPortService>();
builder.Services.AddScoped<IBaseService<Owner>, UserService>();
builder.Services.AddScoped<IBaseService<Feedback>, FeedBackService>();
builder.Services.AddScoped<IBaseService<RentRecord>, RentService>();


builder.Services.AddDbContext<Parking>(option=>{
    option.UseSqlServer(builder.Configuration.GetConnectionString("Default"));
    //取消实体追踪
    option.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
});

//````````````````````````````````````````````````````````````````````````

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
//````````````````````````````
app.UseHttpsRedirection();
app.UseCors("any");
app.UseAuthorization();

//使用中间件
app.UseAuthentication();
app.UseAuthorization();
//```````````````````````````````

app.MapControllers();

app.Run();
